<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    function tap (ele, handler) {
      var flag = true
      var time = 0
      var x,y
      ele.addEventListener('touchstart', function (e) {
        x = e.changedTouches[0].clientX
        y = e.changedTouches[0].clientY
        flag = true
        time = Date.now()
      })

      ele.addEventListener('touchmove', function (e) {
        var movex = e.changedTouches[0].clientX - x,
            movey = e.changedTouches[0].clientY - y,
            move = Math.sqrt(Math.pow(movex, 2) + Math.pow(movey, 2))
        if (move > 6) {
          flag = false
        }
      })

      ele.addEventListener('touchend', function (e) {
        if(flag && Date.now() - time < 300) {
          handler.call(this, e)
        }
      })
    }
    

    function longTap (ele, handler) {
      var flag = true
      var time = 0
      var x,y
      ele.addEventListener('touchstart', function (e) {
        x = e.changedTouches[0].clientX
        y = e.changedTouches[0].clientY
        flag = true
        time = Date.now()
      })

      ele.addEventListener('touchmove', function (e) {
        var movex = e.changedTouches[0].clientX - x,
            movey = e.changedTouches[0].clientY - y,
            move = Math.sqrt(Math.pow(movex, 2) + Math.pow(movey, 2))
        if (move > 6) {
          flag = false
        }
      })

      ele.addEventListener('touchend', function (e) {
        if(flag && Date.now() - time > 700) {
          handler.call(this, e)
        }
      })
    }

    tap(document, function (e) {
      console.log('1')
    })

    /* 
      滑动
      左滑
      右滑
      上滑
      下滑
      
        移动端事件封装

        知乎 用vw布局方案布局

     */
  </script>
</body>
</html>